<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="UTF-8"%>
<%
BoardDao boardDao = new BoardDaoImpl();
TopicDao topicDao = new TopicDaoImpl();
UserDao userDao = new UserDaoImpl();
Map mapBoard = boardDao.findBoard();
%>
<link rel="stylesheet" type="text/css" href="styles.css">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml1-transitional.dtd">
<htmlxmlns = "http://www.w3.org/1999/xhtml">
  <head>
  	<meta http-equiv="Content-Type" content="text/html; charset = utf-8"/>
    <title>欢迎来到-首页</title>
	
	
	
  </head>
  
  <body>
  	<%
        if (application.getAttribute("count") == null) {
            application.setAttribute("count", new Integer(0));
        }
        Integer count = (Integer) application.getAttribute("count");
        application.setAttribute("count", new Integer(count.intValue() + 1));
        count = (Integer) application.getAttribute("count");
    %>
    	<div id="apDiv1">
			<div align ="center" class="STYLE1 textColor navbar-brand">
				<span class="font-weight-bold align-middle ml-3 d-inline-block">校</span>
				<span class="font-weight-bold align-middle ml-3 d-inline-block">园</span>
				<span class="font-weight-bold align-middle ml-3 d-inline-block">B</span>
				<span class="font-weight-bold align-middle ml-3 d-inline-block">B</span>
				<span class="font-weight-bold align-middle ml-3 d-inline-block">S</span>
				<span class="font-weight-bold align-middle ml-3 d-inline-block">系</span>
				<span class="font-weight-bold align-middle ml-3 d-inline-block">统</span>
			  </div>
		</div>
		<%
			if(session.getAttribute("user")==null){
		%>
		<div class="STYLE4" id="apDiv2">
			您尚未<a href="login.jsp" target="_blank">登录</a>
			|
			<a href="reg.jsp" target="_blank" style="color:#fe7300;">注册</a>
		</div>
		<%
			}else{
				User loginUser=(User)session.getAttribute("user");
		%>
		<div class="STYLE4" id="apDiv2">
			您好:<%=loginUser.getUserName() %>
			&nbsp;|&nbsp;<a href="manage/doLogout.jsp">退出</a>
		</div>
		<%
		}
		%>
		<div id="apDiv3">
			<table width="100%" height="503" border="1" cellpadding="0" cellspacing="0" >
				<tr>
					<td colspan="2" align="left" valign="middle">
						<span class="STYLE4 transitional">论坛</span>
					</td>
					<td width="5%" class="STYLE4 transitional">
						主题
					</td>
					<td width="45%" class="STYLE4 transitional">
						最后发表
					</td>
				</tr>

				<!-- 主板块 -->
				<%
				List listMainBoard = (List)mapBoard.get(new Integer(0));
				for(int i=0;i<listMainBoard.size();i++)
				{
					Board mainBoard = ((Board)listMainBoard.get(i));
				%>
				<tr class="tr3">
					<td colspan="4">
						<%=mainBoard.getBoardName() %>
					</td>
				</tr>
				<!-- 子版块 -->
				<%
				List listSonBoard = (List)mapBoard.get(new Integer(mainBoard.getBoardId()));
				for(int j=0 ; j<listSonBoard.size();j++)
				{
					Board sonBoard = (Board)listSonBoard.get(j);
					Topic topic = new Topic();
					User user = new User(); 
					
					int boardId = sonBoard.getBoardId();
					List listTopic  = topicDao.findListTopic(1, boardId);
					if(listTopic!=null&&listTopic.size()>0){
						topic = (Topic)listTopic.get(0);
						user = userDao.findUser(topic.getUserId());
					}
				%>
				<tr class="tr3">
					<td width="5%">
						&nbsp;
					</td>
					<th align="left">
						<img src="image/board.gif" alt="">
						<a href="list.jsp?page=1&boardId=<%=boardId %>">
							<%=sonBoard.getBoardName() %>
						</a>
					</th>
					<td align="center">
						<%=topicDao.findCountTopic(boardId) %>
					</td>
					<th>
						<span>
							<a href="detail.jsp?page=1&boardId=<%=boardId %>&topicId=<%=topic.getTopicId() %>">
								<%=topic.getTitle() %>
							</a>
						</span>
						<br/>
						<span><%=user.getUserName() %></span>
						<span class="gray">
							[<%=topic.getPublishTime() %>]
						</span>
					</th>
				</tr>
				<%
				}
			}
				%>
			</table>
			<left>
        		欢迎！您是第<%=count.intValue()%>个访问者!
    		</left>
		</div>
  </body>
</html>
